package com.spring.housing1.controller.commen;

import com.spring.housing1.constant.Constants;
import com.spring.housing1.constant.PageRequired;
import com.spring.housing1.constant.ServiceTokenRequired;
import com.spring.housing1.constant.isNull;
import com.spring.housing1.pojo.AppointmentInfo;
import com.spring.housing1.pojo.CardInfo;
import com.spring.housing1.returnType.CommenResult;
import com.spring.housing1.server.ExecutorServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;


/*
 * 查询接口
 * */
@RestController
public class QueryControllers {

    private final Logger log = LoggerFactory.getLogger(QueryControllers.class);

    @Autowired
    ExecutorServer loginServer;

    /**
     * 登录前操作获取open_id和session_key，先拿到这两个才能通过微信端拿用户信息(手机号需要认证---废除)
     * */
    @PostMapping("/getSession")
    CommenResult<Object> login(@RequestBody Map<String, String> param, HttpSession httpSession) throws Exception {
        return loginServer.doLogin(param, httpSession);
    }


    /**
     * 获取用户信息
     * */
    @GetMapping("/getUserInfos")
    CommenResult<Object> getUserInfos(@RequestParam("open_id") String  param) throws Exception {
        return loginServer.getUserInfos(param);
    }

    /**
     * 获取就诊卡信息
     * */
    @ServiceTokenRequired
    @isNull({"open_id"})
    @PostMapping("/getCards")
    CommenResult<Object> getCards(@RequestBody CardInfo cardInfo) throws Exception {
        return loginServer.getCards(cardInfo);
    }

    /**
     * 排队取号(多线程时--synchronized锁住对象，每次请求拿到对象锁才能对表进行操作) cardInfo就诊卡信息，type诊断部位,按次序分配一名在诊医师
     * 号码为1-100，可回收机制
     * */
    @ServiceTokenRequired
    @PostMapping("/getAppointment")
    @isNull({"cardInfo","type"})
    CommenResult<Object> getAppointment(@RequestBody AppointmentInfo appointmentInfo) throws Exception {
        return loginServer.getAppointment(appointmentInfo);
    }



    /**
     * 预约撤销(流程为待处理时才能撤销)number预约的号码，name患者姓名，identifyId患者身份证号码
     * */
    @ServiceTokenRequired
    @GetMapping("/cancelAppointment")
    @isNull({"node_id"})
    CommenResult<Object> cancelAppointment(@RequestParam Map<String,String> appointmentInfo)  {
        return loginServer.cancelAppointment(appointmentInfo);
    }
    /**
     * 询问医生撤销(流程为内外科医生待处理时才能撤销)
     * */
    @ServiceTokenRequired
    @GetMapping("/cancelDeal")
    @isNull({"node_id"})
    CommenResult<Object> cancelDeal(@RequestParam Map<String,String> appointmentInfo)  {
        return loginServer.cancelDeal(appointmentInfo);
    }

    /**
     * 获取预约信息
     * @param open_id 用户id
    * */

    @ServiceTokenRequired
    @GetMapping("/getAppointmentInfo")
    @isNull({"open_id"})
    CommenResult<Object> getAppointmentInfo(@RequestParam Map<String,String> appointmentInfo)  {
        return loginServer.getAppointmentInfo(appointmentInfo);
    }

    /**
     * 更新预约信息
     *
     * */

    @ServiceTokenRequired
    @GetMapping("/udateAppointmentInfo")
    CommenResult<Object> udateAppointmentInfo()  {
        return loginServer.udateAppointmentInfo();
    }
    /**
     * 查看报告列表
     * @param open_id 用户id
     * */

    @ServiceTokenRequired
    @GetMapping("/getReportList")
    @isNull({"open_id"})
    CommenResult<Object> getReportList(@RequestParam Map<String,String> appointmentInfo)  {
        return loginServer.getReportList(appointmentInfo);
    }

    /**
     * 查看报告详情
     * @param node_id 病单id
     * */

    @ServiceTokenRequired
    @GetMapping("/getCdInfo")
    @isNull({"node_id"})
    CommenResult<Object> getCdInfo(@RequestParam Map<String,String> appointmentInfo)  {
        return loginServer.getCdInfo(appointmentInfo);
    }

    /**
     * 查询医生信息 无参
     * */
//    @ServiceTokenRequired

    @GetMapping("/queryDoctor")
    CommenResult<Object> pageQuery(@RequestParam Map<String,String> param) throws Exception {
        CommenResult<Object> objectCommenResult = loginServer.queryRoleDoctor(param);
        return objectCommenResult;
    }

    /**
    *  询问内外科医生信息  参数: {node_id}
    * */
//    @ServiceTokenRequired
    @isNull({"node_id","doctor2_id","remark"})
    @GetMapping("/askDoctir")
    CommenResult<Object> askDoctir(@RequestParam Map<String,String> param) throws Exception {
        CommenResult<Object> objectCommenResult = loginServer.askDoctir(param);
        return objectCommenResult;
    }

    /**首页查看消息列表
    * */
    @isNull({"open_id"})
    @GetMapping("/queryMessage")
    CommenResult<Object> queryMessage(@RequestParam Map<String,String> param) throws Exception {
        CommenResult<Object> objectCommenResult = loginServer.queryMessage(param);
        return objectCommenResult;
    }


}
